package rollercoaster.superfonta;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import rollercoaster.superfonta.math.SFMatrix4f;
import rollercoaster.superfonta.math.SFVertex4f;


// This camera allows to see the coach from 

public class Camera1 implements iCameraState,KeyListener{
	
	private SFVertex4f focus4 = new SFVertex4f(-5,0,0,1);
	private SFVertex4f target4 = new SFVertex4f(0,0,0,1);
	private SFVertex4f dir4 = new SFVertex4f();
	private SFVertex4f upV4 = new SFVertex4f(0,1,0,1);
	private SFVertex4f left4 = new SFVertex4f(0,0,1,1);
	private float upL = 1;
	private float leftL = 1;
	
	
	public void setCameraMode(SFCamera camera, SFMatrix4f cameraMatrix) {
		
		
		SFVertex4f focusn = cameraMatrix.multMoP(focus4,true);
		SFVertex4f targetn = cameraMatrix.multMoP(target4, true);
		
		dir4 = new SFVertex4f(targetn.getX()-focusn.getX(),targetn.getY()-focusn.getY(),targetn.getZ()-focusn.getZ(), 1);
		
		SFVertex4f leftn = cameraMatrix.multMoP(left4, false);
		SFVertex4f upVn = cameraMatrix.multMoP(upV4, false);
		
		camera.setF(focusn);
		camera.setUp(upVn);
		camera.setLeft(leftn);
		camera.setDir(dir4);
		camera.setUpL(upL);
		camera.setLeftL(leftL);
		camera.update();
		
	}
	
	public void setFocus4(SFVertex4f focus4) {
		this.focus4 = focus4;
	}

	public void setLeft4(SFVertex4f left4) {
		this.left4 = left4;
	}

	
	
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	
	public void keyPressed(KeyEvent arg0) {
		
		if(arg0.getKeyCode()==KeyEvent.VK_O){
			setFocus4( new SFVertex4f(0,0,5,1));
			setLeft4( new SFVertex4f(1,0,0,1));
		}
		
		if(arg0.getKeyCode()==KeyEvent.VK_I){
			setFocus4( new SFVertex4f(0,0,-5,1));
			setLeft4( new SFVertex4f(-1,0,0,1));
		}
		
		if(arg0.getKeyCode() == KeyEvent.VK_0){
			
			upL = upL * 2;
			leftL = leftL * 2;
			setUpL(upL);
			setLeftL(leftL);
		}
		
		if(arg0.getKeyCode() == KeyEvent.VK_9){
			
			upL = upL / 2;
			leftL = leftL / 2;
			setUpL(upL);
			setLeftL(leftL);
		}
		
	}

	
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}


	public float getUpL() {
		return upL;
	}

	public void setUpL(float upL) {
		this.upL = upL;
	}

	public float getLeftL() {
		return leftL;
	}

	public void setLeftL(float leftL) {
		this.leftL = leftL;
	}


}
